if(yam.$("#__at_ymmr_evt_cntnr").length == 0){
(function(){
var $=yam.$;
function __getFollowing(since){
	$.ajax({
		type:"GET",
		url:"https://www.yammer.com/api/v1/messages/following.json?threaded=true" + (since ? "&older_than=" + since : ""),
		dataType:"json",
		success:function(data){__handleData(data);}
	});	
}

function __handleEvent(attachment){
	var iCalUrl = "/aiit.ac.jp/events/ical/" + attachment.id;
	var inlineUrl = attachment.inline_url;
	var cid = "__at_ymmr_evt_cntnr";
	var container = $("#" + cid);
	if(container.length == 0){
		container = $("<div>",{
			id:cid,
			css:{
				position:"absolute",
				top:"0px",
				left: "0px",
				"background-color": "white",
				"z-Index": 10000
			}
		}).appendTo("body");
	}
	$.ajax({
		type:"GET",
		url:inlineUrl,
		dataType:"html",
		success: function(htm){
			console.log("" + htm);
			$("#"+cid).append(htm);
		}
	});
}

function __handleData(data){
	var items = data.messages || [];
	$.each(items, function(idx, item){
		$.each(item.attachments || [], function(idx, attachment){
			if("ymodule" == attachment.type && attachment.ymodule && "events" == attachment.ymodule.app_id){
				__handleEvent(attachment);
			}
		});
	});
	
	if(items.length > 0){
		__getFollowing(items[items.length - 1].id);
	}
}
__getFollowing();
})();
}